<?php
session_start();
function create_img() {
// tao  ma so ngau nhieu gom 5 ki tu
$md5_hash = md5(rand(0,999)); // so ki tu tao ra co the den 32 ki tu
$security_code = substr($md5_hash,15,8); // lay ra 5 ki tu bat ki tu vi tri thu 15
$_SESSION['security_code'] = $security_code; // de thuc hien so sanh voi ma nhap vao tai trang form
// tao anh
$width = 150;
$height = 30;
// tao anh co kich thucoc dinh tren

$img = imagecreate($width,$height); 

// tao mau cho anh
$red = imagecolorallocate($img,255,255,255); 
$green = imagecolorallocate($img,0,0,0);

// to mau nen cho anh

imagefill($img,0,0,$green);
imagestring($img,10,30,5,$security_code,$red);//(anh,size chu,  can tren, can trai, chuoi, mau chuoi)
//tra ve du lieu dang hinh
header("Content-Type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
}
create_img();
exit();
?>